package com.testing.web.POTest;

import com.testing.InitTest;
import com.testing.class6.RoyPO.ShopAdminPage;
import com.testing.common.AutoTools;
import com.testing.common.ExcelReader;
import com.testing.web.WebKeyword;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/**
 * @Classname ShopBuyPage
 * @Description 按PO设计模式进行封装
 * @Date 2022/10/10 20:08
 * @Created by 特斯汀Roy
 */
public class ShopBuyPageNG extends WebKeyword {
    //url
    private String buyUrl = "http://www.testingedu.com.cn:8000/";

    //管理的元素
    private String 首页登录元素 = "//a[text()='登录']";
    private String 用户名输入框 = "//input[@id='username']";
    private String 密码输入框 = "//input[@id='password']";

    @BeforeClass
    public void startBuyTest() {
        //使用之前的类中的浏览器
        setDriver(InitTest.getWeb().getDriver());
//        openBrowser("chrome");
        visitWeb("{url}");
//        visitWeb(buyUrl);
        click(首页登录元素);
    }

    //搜索商品的业务流程
    @Test(priority = 3)
    public void searchGoods() {
        saveParam("返回xpath", "//a[text()=\"返回商城首页\"]");
        click("{返回xpath}");
        input("//input[@id='q']", "{随机商品}");
        click("//button[text()='搜索']");
        halt("2");

        click("//a[text()='加入购物车']");
        switchFrame("layui-layer-iframe1");
        click("//a[text()='去购物车结算']");
        click("//a[text()='去结算']");
        //实际上大部分网页，浏览器是可以自己完成滚动操作的。
        click("//button[contains(text(),'提交订单')]");
        assertEleText(".erhuh>h3", "提交成功");
        halt("3");
        log.info("参数存储map的内容" + paramMap);
    }

    //登录首页
    @Test(priority = 2,dataProvider = "excel")
    public void loginBuy(String username,String password) {
        input(用户名输入框, username);
        input(密码输入框, password);
        input("//input[@id='verify_code']", "1");
        click("//a[@name=\"sbtbutton\"]");
        click("//a[text()='确定']");
        halt("2");
    }

    @DataProvider(name="lp")
    public Object[][] loginData() {
        return new Object[][]{
                {"roy", "luanqibazao"},
                {"asdfasdf",
                "123456"},
                {"13800138006", "123456"}
        };
    }

    @DataProvider(name="excel")
    public Object[][] loginDataFromExcel(){
        ExcelReader reader=new ExcelReader("Cases/loginData.xlsx");
        return reader.readAsMatrix();
    }




    @AfterClass
    public void close() {
        closeBrowser();
    }


}
